package com.xhs.hawaii.common.utils;

import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import java.io.IOException;

/**
 * @author tangchuang
 * @version 1.0
 * @since 2018/1/25
 */
public class HttpUtils {

    public static String execute(HttpUriRequest request) {
        CloseableHttpClient httpClient = HttpClients.createDefault();
        try {
            String result = httpClient.execute(request, new BasicResponseHandler());
            return result;
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                httpClient.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
